﻿using System;
using System.Collections.Generic;
using System.Linq;
using Lextm.SharpSnmpLib;

namespace SNMS.Manager.Infrastructure
{
    public static class SharpSnmpLibExtension
    {
        public static int ToInt32(this ISnmpData snmpData) {
            switch (snmpData.TypeCode) { 
                case(SnmpType.TimeTicks):
                    return Convert.ToInt32(((TimeTicks)snmpData).ToUInt32());
                case(SnmpType.Integer32):
                    return Convert.ToInt32(((Integer32)snmpData).ToInt32());
                case(SnmpType.Counter32):
                    return Convert.ToInt32(((Counter32)snmpData).ToUInt32());
                case(SnmpType.Gauge32):
                    return Convert.ToInt32(((Gauge32)snmpData).ToUInt32());
            }
            int result = Convert.ToInt32(snmpData);
            return result;
        }
        public static ISnmpData OidValue(this IList<Variable> variables,string oid) {
            var id = new ObjectIdentifier(oid);
            var result = variables.Where(v => v.Id == id);
            if (result.Count() < 1) {
                return null;
            }
            return result.First().Data;
        }
    }
}
